<template>
<div id="paperslist">
  <el-card>
    <div slot="header">
      <span>问卷管理</span>
      <el-button @click="$router.push({name:'papersadd'})" type="primary" size="mini">添加问卷</el-button>
    </div>

    <el-table :data="papersList">
      <el-table-column prop="title" label="标题">
      </el-table-column>
      <el-table-column prop="ctime" label="日期">
       <template slot-scope="{row}">
          {{mom(row.ctime).format('YYYY年MM月DD日hh:mm:ss')}}
       </template>
      </el-table-column>
      <el-table-column prop="username" label="创建人">
      </el-table-column>
      <el-table-column prop="classname" label="班级">
      </el-table-column>
      <el-table-column label="操作">
        <div slot-scope="{row}">
          <el-button type="text" @click="del(row.id)">删除</el-button>
          <el-button type="text" @click="$router.push({name:'papersedit',params:{id:row.id}})">编辑</el-button>
          <el-button type="text" @click="$router.push({name:'publish',params:{paper_id:row.id}})">发布</el-button>
          <el-button type="text"  @click="$router.push({name:'count',params:{paper_id:row.id}})">分析</el-button>

        </div>
      </el-table-column>

    </el-table>
  </el-card>
</div>
</template>

<script>
export default {
  data() {
    return {
      papersList: []
    };
  },
  created() {
    this.getPapersList();
  },
  methods: {
    del(id) {
      this.$confirm("是否继续?", "提示", {
          type: "warning"
        })
        .then(() => {
          this.$http
            .get("/papers/delete", {
              params: {
                id
              }
            })
            .then(result => {
              this.getPapersList();
            });
        })
        .catch(() => {
        });
    },
    getPapersList() {
      this.$http
        .get("/papers/list", {
          params: {
            pagesize: 10,
            currentpage: 1
          }
        })
        .then(result => {
          this.papersList = result.data.data;
        });
    }
  }
};
</script>
